﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Web;

namespace Utility
{
    public class Log
    {
        public static void LogWriter(string Log,string LogFileName,string LogFolder)
        {
            if (string.IsNullOrEmpty(LogFileName)) { LogFileName = DateTime.Now.ToString("yyyyMMdd") + ".txt"; }
            if (string.IsNullOrEmpty(LogFolder)) { LogFolder =HttpContext.Current.Server.MapPath( "/Log/" + DateTime.Now.ToString("yyyyMM")+"/"); }
            if (!Directory.Exists(LogFolder)) { Directory.CreateDirectory(LogFolder); }
            if (!File.Exists(LogFolder + LogFileName)) { System.IO.FileStream Cfs = File.Create(LogFolder + LogFileName); Cfs.Close(); }
            System.IO.FileStream Fs = new FileStream(LogFolder + LogFileName, FileMode.Append);
            System.IO.StreamWriter Sw = new StreamWriter(Fs, System.Text.Encoding.Default);
            Sw.WriteLine(DateTime.Now.ToString() + "  " + Log);
            Sw.Close();
            Fs.Close();
        }
        public static void LogWriter(string Log)
        {
            LogWriter(Log, "", "");
        }
    }
}
